package com.iexbuy.ihg.ui.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.TextView;

import com.iexbuy.ihg.App;
import com.iexbuy.ihg.R;
import com.iexbuy.ihg.common.CommUtil;
import com.iexbuy.ihg.net.ServiceHelper;
import com.iexbuy.ihg.utils.JsonUtils;
import com.iexbuy.ihg.utils.StringUtil;
import com.iexbuy.ihg.utils.ToastUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

import java.util.HashMap;

public class WeDeAboutFragment extends BaseFragment {

	private static WeDeAboutFragment homeFragmentInstent;

	@ViewInject(R.id.aboutText)
	private WebView aboutText;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		homeFragmentInstent = this;
	}

	@Override
	protected View _onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.fragment_wede_about, container, false);
		ViewUtils.inject(this, rootView);
		initView(rootView);
		return rootView;
	}

	private void initView(View rootView) {
		mBaseActivity.setTitle(getResources().getString(R.string.we_de_about));
		mBaseActivity.setTitleLayoutVisibility(true);
		mBaseActivity.setHomeActivity(false);

		getAboutInfo();
	}


	public void getAboutInfo() {
		HashMap<String, String> paramMap = new HashMap<String, String>();
		ServiceHelper.send(mBaseActivity, ServiceHelper.GET_ABOUT, paramMap,
				new RequestCallBack<String>() {
					@Override
					public void onStart() {
					}

					@Override
					public void onCancelled() {
					}

					@Override
					public void onSuccess(ResponseInfo<String> responseInfo) {
						String aboutTextStr = JsonUtils.getJsonSubStringByKey(JsonUtils.getJsonSubStringByKey(responseInfo.result, "body"), "body");
						CommUtil.loadWebviewData(aboutText, aboutTextStr);
					}

					@Override
					public void onFailure(HttpException error, String msg) {
						ToastUtils.toast(mBaseActivity, msg);
					}
				});
	}

	/**
	 * @return the homeFragmentInstent
	 */
	public static WeDeAboutFragment getHomeFragmentInstent() {
		return homeFragmentInstent;
	}

}
